// functionPage/pages/review/operatorDetail/operatorDetail.js
import Http from '../../../../utils/http.js';
const http = new Http();
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        review: '',
        id: '',
        operator: {},
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            review: options.review,
            id: options.id,
        });
        this.getCityOperatorDetail(options.id, options.country, options.city);
    },

    getCityOperatorDetail(id, country, city) {
        let data = {
            authId: app.globalData.authId,
            id,
            country,
            city,
        };
        http.getRequest('cjMap/getCityOperatorDetail', data).then((res) => {
            if (res.status == 0) {
                let operator = res.cityOperator;
                let tempNetworkSupportArr = [
                    {
                        name: 'NR',
                        value: '00',
                        checked: false,
                    },
                    {
                        name: 'VoLTE',
                        value: '06',
                        checked: false,
                    },
                    {
                        name: 'ViLTE',
                        value: '03',
                        checked: false,
                    },
                    {
                        name: 'VoWiFi',
                        value: '02',
                        checked: false,
                    },
                    {
                        name: 'ViWiFi',
                        value: '01',
                        checked: false,
                    },
                    {
                        name: 'LTE',
                        value: '04',
                        checked: false,
                    },
                    {
                        name: '3G',
                        value: '07',
                        checked: false,
                    },
                    {
                        name: '2G',
                        value: '08',
                        checked: false,
                    },
                ];
                if (operator.networksupport.includes('00')) {
                    tempNetworkSupportArr[0].checked = true;
                }
                if (operator.networksupport.includes('01')) {
                    tempNetworkSupportArr[4].checked = true;
                }
                if (operator.networksupport.includes('02')) {
                    tempNetworkSupportArr[3].checked = true;
                }
                if (operator.networksupport.includes('03')) {
                    tempNetworkSupportArr[2].checked = true;
                }
                if (operator.networksupport.includes('04')) {
                    if (operator.networksupport.includes('05')) {
                        tempNetworkSupportArr[5].name = 'TD/FDD-LTE';
                    } else {
                        tempNetworkSupportArr[5].name = 'TD-LTE';
                    }
                    tempNetworkSupportArr[5].checked = true;
                } else if (operator.networksupport.includes('05')) {
                    tempNetworkSupportArr[5].checked = true;
                    tempNetworkSupportArr[5].name = 'FDD-LTE';
                }
                if (operator.networksupport.includes('06')) {
                    tempNetworkSupportArr[1].checked = true;
                }
                if (operator.networksupport.includes('07')) {
                    tempNetworkSupportArr[6].checked = true;
                    tempNetworkSupportArr[6].name = 'WCDMA';
                }
                if (operator.networksupport.includes('08')) {
                    tempNetworkSupportArr[6].checked = true;
                    tempNetworkSupportArr[6].name = 'CDMA2000';
                }
                if (operator.networksupport.includes('09')) {
                    tempNetworkSupportArr[6].checked = true;
                    tempNetworkSupportArr[6].name = 'TD-SCDMA';
                }
                if (operator.networksupport.includes('10')) {
                    tempNetworkSupportArr[7].checked = true;
                    tempNetworkSupportArr[7].name = 'GSM';
                }
                if (operator.networksupport.includes('11')) {
                    tempNetworkSupportArr[7].checked = true;
                    tempNetworkSupportArr[7].name = 'CDMA1x';
                }
                operator.apnArr = JSON.parse(operator.apnpoint);
                operator.networksupport = tempNetworkSupportArr;
                operator.ussd = JSON.parse(operator.ussd);
                if (operator.lte) {
                    // 基站 E-UTRAN
                    operator.lte.basestationdevicemanufacturer = operator.lte
                        .basestationdevicemanufacturer
                        ? operator.lte.basestationdevicemanufacturer.split(',')
                        : [''];
                    // 核心网 EPC
                    operator.lte.corenetdevicemanufacturer = operator.lte
                        .corenetdevicemanufacturer
                        ? operator.lte.corenetdevicemanufacturer.split(',')
                        : [''];
                    // IP多媒体系统 IMS
                    operator.lte.ipmediadevicemanufacturer = operator.lte
                        .ipmediadevicemanufacturer
                        ? operator.lte.ipmediadevicemanufacturer.split(',')
                        : [''];
                    // 频段支持 Band
                    operator.lte.channelname = operator.lte.channelname || '';
                    // 区域划分界限
                    operator.lte.regionlimit = operator.lte.regionlimit || '';
                }

                if (operator.nr) {
                    // 基站 NG-RAN
                    operator.nr.basestationdevicemanufacturer = operator.nr
                        .basestationdevicemanufacturer
                        ? operator.nr.basestationdevicemanufacturer.split(',')
                        : [''];
                    // 核心网 5GC
                    operator.nr.corenetdevicemanufacturer = operator.nr
                        .corenetdevicemanufacturer
                        ? operator.nr.corenetdevicemanufacturer.split(',')
                        : [''];
                    // 频段支持 Band
                    operator.nr.channelname = operator.nr.channelname || '';
                    // 区域划分界限
                    operator.nr.regionlimit = operator.nr.regionlimit || '';
                }

                this.setData({
                    operator,
                });

                wx.setNavigationBarTitle({
                    title: operator.country,
                });
            }
        });
    },

    // 预览图片
    previewApnImage(e) {
        let { index, apnpoint } = e.currentTarget.dataset;

        apnpoint = JSON.parse(apnpoint);

        wx.previewImage({
            current: apnpoint[index].sceneImageArr[0],
            urls: apnpoint[index].sceneImageArr,
        });
    },

    // 复制
    copyText: function (e) {
        wx.setClipboardData({
            data: e.currentTarget.dataset.content,
            success: function (res) {
                wx.getClipboardData({
                    success: function (res) {},
                });
            },
        });
    },

    //打电话
    callPhone(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone,
        });
    },
});
